package com.protocols.sctp.m3ua.sccp.tcap;

import com.protocols.GeneralProtocolData;
import com.protocols.OctaveInteger;
import com.protocols.ProtoOperations;
import com.protocols.ProtocolStackException;
import com.protocols.sctp.m3ua.sccp.SccpUnitDataMsg;

public class TcapAbort implements GeneralProtocolData{

	private TcapConstructor Abort = new TcapConstructor(0x67);
	private TcapPrimitiveUnitNumber DestinationTransactionID = new TcapPrimitiveUnitNumber(0x49);
	private TcapPrimitiveUnitNumber AbortCause = new TcapPrimitiveUnitNumber(0x49);
	private TcapConstructor DialogPortion = new TcapConstructor(0x6b);
	private TcapConstructor External = new TcapConstructor(0x28);
	private TcapPrimitiveUnitByteArray ObjectID = new TcapPrimitiveUnitByteArray(0x06);
	private TcapConstructor DialogAsID = new TcapConstructor(0xA0);
	private TcapConstructor DialogAbortPDU = new TcapConstructor(0x64);
	private TcapPrimitiveUnitNumber AbortSource = new TcapPrimitiveUnitNumber(0x80);
	private TcapConstructor UserInformationContainer = new TcapConstructor(0xbe);	
	private TcapPrimitiveUnitByteArray UserInformation = new TcapPrimitiveUnitByteArray(0x28);	
	public TcapAbort() {

		Abort.addElement(DestinationTransactionID);	
		Abort.addElement(DialogPortion);
		DialogPortion.addElement(External);
		External.addElement(ObjectID);
		External.addElement(DialogAsID);
		DialogAsID.addElement(DialogAbortPDU);
		DialogAbortPDU.addElement(AbortSource);
		DialogAbortPDU.addElement(UserInformationContainer);
		UserInformationContainer.addElement(UserInformation);
		
	}

	
	
	public void setObjectID(byte[] objectid){
		ObjectID.setTagValue(objectid);
	}
	
	public byte[] getObjectID(){
		return ObjectID.getTagValue();
	}
	
	public byte [] getByteArray(){	
		return Abort.getByteArray();
		

	}
	
	
	public int getLength(){
		return getByteArray().length;
	}
	

	public long getDestinationTransactionID() {
		return DestinationTransactionID.getTagValue();
	}

	public void setDestinationTransactionID(long destinationTransactionID) {
		DestinationTransactionID.setTagValue( destinationTransactionID);
	}
	
	public long getAbortSource() {
		
		return AbortSource.getTagValue();
	}

	public void setAbortSource(long abortSource) {
		AbortCause.setVisible(false);
		AbortSource.setTagValue( abortSource);
	}
	
	public long getAbortCause() {
		return AbortCause.getTagValue();
	}

	public void setAbortCause(long abortCause) {
		AbortSource.setVisible(false);
		UserInformation.setVisible(false);
		AbortCause.setTagValue( abortCause);
	}
	

	@Override
	public byte[] decode(byte[] input) throws ProtocolStackException {
		input=ProtoOperations.extractByteArray(input, 1, input.length-1);
		
		return Abort.decode(input);
	}

	
	
	
}
